package com.yike.user.controller;

import com.yike.user.param.*;
import com.yike.user.service.AgentWithdrawalService;
import com.yike.user.vo.*;
import lombok.extern.slf4j.Slf4j;
import com.yike.common.base.BaseController;
import com.yike.common.api.ApiResult;
import com.yike.common.pagination.Paging;
import com.yike.common.log.Module;
import com.yike.common.log.OperationLog;
import com.yike.common.enums.OperationLogType;
import org.springframework.validation.annotation.Validated;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 代理商提现申请表 控制器
 *
 * @author Sakura
 * @since 2024-09-23
 */
@Slf4j
@RestController
@RequestMapping("/agentWithdrawal")
@Module("user")
@Api(value = "代理商提现API", tags = {"代理商提现管理"})
public class AgentWithdrawalController extends BaseController {

    @Autowired
    private AgentWithdrawalService agentWithdrawalService;

    /**
     * 获取用户银行账户信息列表
     */
    @PostMapping("/getWithdrawalInfo")
    //@OperationLog(name = "获取提现信息", type = OperationLogType.INFO)
    @ApiOperation(value = "获取提现信息", response = WithdrawalInfoVo.class)
    public ApiResult<WithdrawalInfoVo> getWithdrawalInfo(@RequestBody WithdrawalInfoParam withdrawalInfoParam) throws Exception {
        WithdrawalInfoVo withdrawalInfoVo = agentWithdrawalService.getWithdrawalInfo(withdrawalInfoParam);
        return ApiResult.ok(withdrawalInfoVo);
    }

    /**
     * 获取用户银行账户信息列表
     */
    @GetMapping("/getBankAccountList")
    //@OperationLog(name = "获取银行账号列表", type = OperationLogType.INFO)
    @ApiOperation(value = "获取银行账号列表", response = UserBankAccountVo.class)
    public ApiResult<List<UserBankAccountVo>> getBankAccountList() throws Exception {
        List<UserBankAccountVo> userBankAccountVos = agentWithdrawalService.getBankAccountList();
        return ApiResult.ok(userBankAccountVos);
    }

    /**
     * 获取用户银行账户信息列表
     */
    @GetMapping("/getAgentCommissionInfo")
    //@OperationLog(name = "获取代理商分润信息", type = OperationLogType.INFO)
    @ApiOperation(value = "获取代理商分润信息", response = AgentCommissionInfoVo.class)
    public ApiResult<AgentCommissionInfoVo> getAgentCommissionInfo() throws Exception {
        AgentCommissionInfoVo agentCommissionInfo = agentWithdrawalService.getAgentCommissionInfo();
        return ApiResult.ok(agentCommissionInfo);
    }

    @PostMapping("/bindingBank")
    @OperationLog(name = "绑定银行账号", type = OperationLogType.ADD)
    @ApiOperation(value = "绑定银行账号", response = ApiResult.class)
    public ApiResult<Boolean> bindingBank(@RequestBody BindingBankParam bindingBankParam) throws Exception {
        boolean flag = agentWithdrawalService.bindingBank(bindingBankParam);
        return ApiResult.result(flag);
    }

    @PostMapping("/apply")
    @OperationLog(name = "申请提现", type = OperationLogType.ADD)
    @ApiOperation(value = "申请提现", response = ApiResult.class)
    public ApiResult<Boolean> withdrawalApply(@RequestBody AgentWithdrawalApplyParam agentWithdrawalApplyParam) throws Exception {
        boolean flag = agentWithdrawalService.withdrawalApply(agentWithdrawalApplyParam);
        return ApiResult.result(flag);
    }

    @PostMapping("/check")
    @OperationLog(name = "提现审核", type = OperationLogType.ADD)
    @ApiOperation(value = "提现审核", response = ApiResult.class)
    public ApiResult<Boolean> withdrawalCheck(@RequestBody AgentWithdrawalCheckParam agentWithdrawalCheckParam) throws Exception {
        boolean flag = agentWithdrawalService.withdrawalCheck(agentWithdrawalCheckParam);
        return ApiResult.result(flag);
    }

    /**
     * 获取代理商提现申请表详情
     */
    @GetMapping("/info/{id}")
    //@OperationLog(name = "提现申请详情", type = OperationLogType.INFO)
    @ApiOperation(value = "提现申请详情", response = AgentWithdrawalApplyVo.class)
    public ApiResult<AgentWithdrawalApplyVo> getAgentWithdrawalApply(@PathVariable("id") Long id) throws Exception {
        AgentWithdrawalApplyVo agentWithdrawalApplyVo = agentWithdrawalService.getAgentWithdrawalApply(id);
        return ApiResult.ok(agentWithdrawalApplyVo);
    }

    /**
     * 代理商提现记录列表
     */
    @GetMapping("/getWithdrawalRecords/{id}")
    //@OperationLog(name = "获取提现操作记录", type = OperationLogType.PAGE)
    @ApiOperation(value = "获取提现操作记录", response = AgentWithdrawalRecordVo.class)
    public ApiResult<List<AgentWithdrawalRecordVo>> getWithdrawalRecords(@PathVariable("id") Long id) throws Exception {
        List<AgentWithdrawalRecordVo> agentWithdrawalRecordVos = agentWithdrawalService.getWithdrawalRecords(id);
        return ApiResult.ok(agentWithdrawalRecordVos);
    }

    /**
     * 代理商提现申请表分页列表
     */
    @PostMapping("/getPageList")
    //@OperationLog(name = "提现申请分页列表", type = OperationLogType.PAGE)
    @ApiOperation(value = "提现申请分页列表", response = AgentWithdrawalApplyVo.class)
    public ApiResult<Paging<AgentWithdrawalApplyVo>> getAgentWithdrawalApplyPageList(@Validated @RequestBody AgentWithdrawalApplyPageParam agentWithdrawalApplyPageParam) throws Exception {
        Paging<AgentWithdrawalApplyVo> paging = agentWithdrawalService.getAgentWithdrawalApplyPageList(agentWithdrawalApplyPageParam);
        return ApiResult.ok(paging);
    }

}

